<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div class="modal fade" id="ocean-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 1000px; height: auto">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <c:choose>
                    <c:when test="${entity.id != null && entity.id!= ''}">
                        <h4 class="modal-title">编辑微信用户</h4>
                    </c:when>
                    <c:otherwise>
                        <h4 class="modal-title">新增微信用户</h4>
                    </c:otherwise>
                </c:choose>
            </div>
            <div class="modal-body">
                <div class=" form">
                    <form class="cmxform form-horizontal tasi-form" id="wxUser_from" method="post"
                          data-url="resources/entity"
                          data-class="com.ocean.billboard.entity.WxUser">
                        <input type="hidden" id="entity_id" name="id" value="${entity.id}">
                        <div class="form-group">
                            <label for="realName" class="control-label col-lg-2">真实姓名 </label>
                            <div class="col-lg-10">
                                <input class="form-control" id="realName" name="realName" type="text" placeholder="真实姓名"
                                       value="${entity.realName}"
                                       required/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="phone" class="control-label col-lg-2">手机号码 </label>
                            <div class="col-lg-10">
                                <input class="form-control" id="phone" name="phone" type="text" placeholder="手机号码"
                                       value="${entity.phone}"
                                       required minlength="11" maxlength="11"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="role1" class="control-label col-lg-2">角色 </label>
                            <div class="col-lg-10">
                                <select class="form-control" id="role1" name="role" onchange="selectOrgId()" required>
                                    <option value=""></option>
                                    <option value="AD_COMPANY"
                                            <c:if test="${entity.role=='AD_COMPANY'}">selected</c:if>>广告公司
                                    </option>
                                    <option value="SUPERVISION_DEPT"
                                            <c:if test="${entity.role=='SUPERVISION_DEPT'}">selected</c:if>>监管部门
                                    </option>
                                    <option value="INSURANCE_COMPANY"
                                            <c:if test="${entity.role=='INSURANCE_COMPANY'}">selected</c:if>>保险公司
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="orgId" class="control-label col-lg-2">所属组织 </label>
                            <div class="col-lg-10">
                                <select class="form-control" id="orgId" name="orgId" required>
                                    <option value=""></option>
                                    <c:forEach items="${org}" var="item">
                                        <option value="${item.id}"
                                                <c:if test="${entity.orgId==item.id}">selected</c:if>>${item.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-success" type="button" onclick="formSubmit(validator)">Save
                                </button>
                                <button class="btn btn-default" type="button" data-dismiss="modal">Cancel</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript" src="static/assets/jquery-ui/jquery-ui-1.10.1.custom.min.js"></script>
<script type="application/javascript">
    var validator = $("#wxUser_from").validate();

    function selectOrgId() {
        $('#orgId').empty();
        var roles = $('#role1').val();
        if (roles == "AD_COMPANY") {
            WaitingDialog.show();
            $.post("resources/adCompany/val", {}, function (data) {
                WaitingDialog.dismiss();
                loadOrgId(data);
            });
        } else if (roles == "SUPERVISION_DEPT") {
            WaitingDialog.show();
            $.post("resources/supervisionDept/val", {}, function (data) {
                WaitingDialog.dismiss();
                loadOrgId(data);
            });
        } else if (roles == "INSURANCE_COMPANY") {
            WaitingDialog.show();
            $.post("resources/insuranceCompany/val", {}, function (data) {
                WaitingDialog.dismiss();
                loadOrgId(data);
            });
        }
    }

    function loadOrgId(data) {
        $('#orgId').html('<option value=""></option>');
        $.each(data, function (index, item) {
            $('#orgId').append('<option value="' + item.id + '"  <c:if test="${item.id!=null && entity.orgId==item.id}">selected</c:if> >' + item.name + '</option>');
        });
    }
</script>
